package com.flexcloudsdk.channel;

import java.util.logging.Logger;

import com.google.appengine.api.channel.ChannelMessage;
import com.google.appengine.api.channel.ChannelService;
import com.google.appengine.api.channel.ChannelServiceFactory;

public class CloudChannelService {
	private ChannelService service;
	private String sourceClass;
	private String sourceMethod;
	private static final Logger log = Logger.getLogger(CloudChannelService.class.getName());

	public CloudChannelService() {
		sourceMethod = Thread.currentThread().getStackTrace()[1].getMethodName().toString();
		sourceClass = CloudChannelService.class.getName();
		log.info("CloudChannelService has been created by BlazeDS");
		service = ChannelServiceFactory.getChannelService();
	}

	public String createChannel(String clientId) {
		sourceMethod = Thread.currentThread().getStackTrace()[1].getMethodName().toString();
		log.info("Executing: " + sourceClass + "." + sourceMethod);
		return service.createChannel(clientId);
	}

	public void sendMessage(ChannelMessage message) {
		sourceMethod = Thread.currentThread().getStackTrace()[1].getMethodName().toString();
		log.info("Executing: " + sourceClass + "." + sourceMethod);
		service.sendMessage(message);
	}
}
